<?php
	session_start();
	require_once("dbc.php");
	require_once("functions.php");
?>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Memoryspel</title>
		<script type="text/javascript" src="script/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="script/jquery-ui-1.8.6.custom.min.js"></script>
		<script type="text/javascript" src="script/jquery.ui.draggable.min.js"></script>
		<script type="text/javascript" src="script/jquery.ui.droppable.min.js"></script>
		<script type="text/javascript" src="script/jquery.effects.highlight.min.js"></script>
		<script type="text/javascript" src="script/script.js"></script>
		<link rel="stylesheet" type="text/css" href="styles/style.css">

		<script type="text/javascript" src="script/jquery-1.4.3.js"></script>
		<script type="text/javascript" src="jquery-ui-1.8.6.custom.min.js"></script>
		<script type="text/javascript" src="script/script.js"></script>



	</head>
	
  <body>
	<div id="main">	

<?php

		if (isset($_GET['page'])) {
			$page=$_GET['page'];
			

			switch($page) {
				
				case "home":	
					login();
					
					if (isset($_SESSION['id']) && isset($_SESSION['username'])) {
						printMainPage();
						printHeader();

					}
					else {
						echo '<div id="frontbkg">';
						printLoginForm();
						printFrontText();
						echo '<img src="images/siteimages/frontImg.png" />';
						echo '</div>';


					}
				break;
				
				case "uploadimg":
					if (isset($_SESSION['id']) && isset($_SESSION['username'])) {
					
						if (isset($_POST['uploadImg'])){
							printHeader();
							fileUpload();
							processImages();	
							printImagePage();
							printImages();

							
						}		
						elseif (isset($_GET['defaultimgbtn'])) {		
							
							$defaultimgbtn = $_GET['defaultimgbtn'];	
							if ($defaultimgbtn == "images") {
								printHeader();
								printImagePage();
								printImages();
							}		
						}
						else {  
							printHeader();
							printUploadpage();
							printImageUploadForm();
						}
					}
					else {
						echo '<div id="frontbkg">';
						printLoginForm();
						printFrontText();
						echo '<img src="images/siteimages/frontImg.png" />';
						echo '</div>';
					}
				break;
				
				case "selectbg":
					printHeader();
					printBackgroundPage();
					printBgImages();
				break;
				
						
				case "register":
					if (isset($_POST['submitRegister'])){
						registerUser();
						confirmRegistration();
						echo '<img id="logo" src="images/siteimages/memorylogo.png">';

					} 
					else {
						echo '<img id="logo" src="images/siteimages/memorylogo.png">';
						printRegisterForm();


					}
				break;
					
				case "logout":
					$_SESSION = array();
					echo '<div id="frontbkg">';
					printLoginForm();
					printFrontText();
					echo '<img src="images/siteimages/frontImg.png" />';
					echo '</div>';
				break;
			
				default: 
					
					echo '<div id="thumbContainer">';
					echo '<img src="images/siteimages/grid2.png" />';
					echo'</div>';
					echo '<img id="errorbkg" src="images/siteimages/startgamebkg.png">';
					echo '<div id="errortext">';
					echo '<p>Error, sidan du söker efter finns inte, 
					<a class="pinkText" href="index.php?page=main"> gå tillbaka</p></a>';
					echo '</div>';
					printHeader();
				}
		}	
		else{
			echo '<div id="frontbkg">';
			printLoginForm();
			printFrontText();
			echo '<img src="images/siteimages/frontImg.png" />';
			echo '</div>';				
		}
	
								
?>
	</div>
  </body>
</html>